package com.etoak.controller;


import com.etoak.common.core.UserVo.PageVO;
import com.etoak.common.core.UserVo.ResultVO;
import com.etoak.entity.Ingredients;
import com.etoak.service.IngredientsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author et2403
 * @since 2024-08-13
 */
@RestController
@RequestMapping("/ingredients")
public class IngredientsController {

    @Autowired
    IngredientsService ingredientsService;

    @PostMapping("/add")
    public ResultVO<Object> add(@Validated @RequestBody Ingredients ingredients){
        ingredientsService.add(ingredients);
        return ResultVO.success();
    }

    @GetMapping
    public ResultVO<PageVO<Ingredients>> getList(@RequestParam(required = false , defaultValue = "1") int pageNum,
                                                  @RequestParam(required = false , defaultValue = "10") int pageSize,
                                                 Ingredients ingredients){
        PageVO<Ingredients> pageVO = ingredientsService.getList(pageNum,pageSize,ingredients);
        return ResultVO.success(pageVO);
    }

    /**
     * 更新接口
     * @param id
     * @param ingredients
     * @return
     */
    @PutMapping("/{id}")
    public ResultVO<Object> update(@PathVariable int id,@Validated @RequestBody Ingredients ingredients){

        ingredientsService.update(id,ingredients);
        return ResultVO.success();
    }

    @DeleteMapping("/{id}")
    public ResultVO<Object> delete(@PathVariable int id){
        ingredientsService.delete(id);
        return ResultVO.success();
    }

}

